package com.hlmc.controller;

import com.hlmc.entity.Banner;
import com.hlmc.entity.FuLi_Video;
import com.hlmc.entity.Page;
import com.hlmc.service.FlService;
import com.hlmc.service.Query_360_Service;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class FlController {

@Resource
private Query_360_Service query_360;
@Resource
private FlService fl_service;
    @ResponseBody
    @RequestMapping("/v_fl")
    public List<FuLi_Video> videoPage(@RequestParam(defaultValue = "1") int page){

        Map<String,Object> map=new HashMap<String, Object>();
        int pageSize=12;
        int totalRecord=fl_service.findTotalNum();
        Page<FuLi_Video> coverPage = new Page<FuLi_Video>(pageSize, page, totalRecord, null);
        int start = (coverPage.getCurrentPage() - 1) * pageSize;
        map.put("start", start);
        map.put("size", pageSize);
        List<FuLi_Video> cover=new ArrayList<FuLi_Video>();
        cover=fl_service.findFlpage(map);
        return cover;
    }

    @RequestMapping("/v_fl2")
    public String videoPage2(@RequestParam(defaultValue = "1") int page, Model model){

        Map<String,Object> map=new HashMap<String, Object>();
        int pageSize=24;
        int totalRecord=fl_service.findTotalNum();
        Page<FuLi_Video> coverPage = new Page<FuLi_Video>(pageSize, page, totalRecord, null);
        int start = (coverPage.getCurrentPage() - 1) * pageSize;
        map.put("start", start);
        map.put("size", pageSize);
        List<FuLi_Video> cover=new ArrayList<FuLi_Video>();
        cover=fl_service.findFlpage(map);
        List<Banner> banners=new ArrayList<Banner>();
        banners=query_360.findBner();
        model.addAttribute("listCover",cover);
        model.addAttribute("banners",banners);
        model.addAttribute("totalRecord",totalRecord);
        model.addAttribute("pageUrl","v_fl2.do?page=");
        model.addAttribute("curr",page);
        model.addAttribute("baseurl","dfl");
        return "index";
    }
}
